﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AdministratorHelper
{
    public partial class AdminForm : Form
    {
        public AdminForm()
        {
            InitializeComponent();
        }

        private void AdminForm_FormClosing(object sender, FormClosingEventArgs e)
        {

        }
        private AppDb db = new AppDb();

        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.Multiselect = false;
            openFileDialog1.Filter = "可执行文件|*.exe";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string name = openFileDialog1.FileName;
                int index = name.LastIndexOf("\\");
                string sortName = name.Substring(index + 1);
                db.Create(new AppModel
                {
                    AppPath = openFileDialog1.FileName,
                    AppName = sortName
                });
            }
            listBox1.Items.Clear();
            List<AppModel> list = db.GetAll();
            foreach (var item in list)
            {
                listBox1.Items.Add(item.AppName);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void AdminForm_Load(object sender, EventArgs e)
        {
            List<AppModel> list = db.GetAll();
            foreach (var item in list)
            {
                listBox1.Items.Add(item.AppName);
            }
        }
    }
}
